<template>
  <div class="app-container">
    <!--工具栏-->
    <div class="head-container">
      <crudOperation :permission="permission">
      </crudOperation>
      <!--表单组件-->
      <el-dialog :close-on-click-modal="false" :before-close="crud.cancelCU" :visible.sync="crud.status.cu > 0"
                 :title="crud.status.title" width="500px">
        <el-form ref="form" :model="form" :rules="rules" size="small" label-width="100px">
          <el-form-item label="编码" prop="code">
            <el-input v-model="form.code" style="width: 370px;"/>
          </el-form-item>
          <el-form-item label="名称" prop="name">
            <el-input v-model="form.name" style="width: 370px;"/>
          </el-form-item>
          <!--          <el-form-item label="商品品牌类型">
                      <el-select v-model="form.type" class="edit-input" placeholder="请选择" style="width: 370px;">
                        <el-option
                            v-for="(item,index) in dict.t_bas_goods_brand_type"
                            :key="index"
                            v-if="item.seq>0"
                            :label="item.label"
                            :value="item.value"
                        />
                      </el-select>
                    </el-form-item>-->
          <el-row :gutter="10">
            <el-col :span="12">
              <el-form-item label="是否采购">
                <!--            <el-input v-model="form.isBuy" style="width: 370px;"/>-->
                <el-switch
                    v-model="form.isBuy"
                    active-color="#13ce66"
                    :active-value="1"
                    :inactive-value="0"
                    inactive-color="#ff4949">
                </el-switch>
              </el-form-item>
            </el-col>
            <el-col :span="12">
              <el-form-item label="是否销售">
                <el-switch
                    v-model="form.isSale" :active-value="1"
                    :inactive-value="0"
                    active-color="#13ce66"
                    inactive-color="#ff4949">
                </el-switch>
              </el-form-item>
            </el-col>
            <el-col :span="12">
              <el-form-item label="是否退货">
                <el-switch
                    v-model="form.isReturn" :active-value="1"
                    :inactive-value="0"
                    active-color="#13ce66"
                    inactive-color="#ff4949">
                </el-switch>
              </el-form-item>
            </el-col>
            <el-col :span="12">
              <el-form-item label="是否零单价">
                <el-switch
                    v-model="form.isZeroPrice"
                    :active-value="1"
                    :inactive-value="0"
                    active-color="#13ce66"
                    inactive-color="#ff4949">
                </el-switch>
              </el-form-item>
            </el-col>
          </el-row>
          <el-form-item label="配置名称" prop="configName">
            <el-input v-model="form.configName" style="width: 370px;"/>
          </el-form-item>
          <el-form-item label="状态">
            <el-select v-model="form.status" class="edit-input" placeholder="请选择" style="width: 370px;">
              <el-option
                  v-for="(item,index) in dict.common_status"
                  :key="index"
                  v-if="item.seq>0"
                  :label="item.label"
                  :value="item.value"
              />
            </el-select>
          </el-form-item>
          <el-form-item label="排序">
            <el-input-number v-model="form.seq" :min="1" label="排序" style="width: 370px;"></el-input-number>
          </el-form-item>
          <el-form-item label="备注">
            <el-input v-model="form.remark" style="width: 370px;" type="textarea"/>
          </el-form-item>
        </el-form>
        <div slot="footer" class="dialog-footer">
          <el-button type="text" @click="crud.cancelCU">取消</el-button>
          <el-button :loading="crud.cu === 2" type="primary" @click="crud.submitCU">确认</el-button>
        </div>
      </el-dialog>

      <vue-context-menu :contextMenuData="contextMenuData"
                        @tableConfig="tableConfig"
                        @deletedata="deletedata"></vue-context-menu>
      <!-- 表格配置 -->
      <el-dialog title="表格配置"
                 :visible.sync="tableConfigShow"
                 width="60%">
        <j-table-column-config :columns.sync="crud.header"  @tabSave="tabSave" @pit="pit" />
      </el-dialog>

      <!--表格渲染-->
      <el-table ref="table"  border
                height="700"
                show-summary
                @cell-dblclick="row=>crud.toEdit(row)"
                v-loading="crud.loading"
                :data="crud.data"
                size="small"
                style="width: 100%;"
                v-if="isShowTable"
                @header-dragend="changeColWidth"
                @contextmenu.native="showMenu"
                :summary-method="crud.sumRow"
                @row-click="crud.selectRow"
                :row-style="crud.rowClass"
                :row-class-name="crud.tableRowClassName"
                @selection-change="crud.selectionChangeHandler">
        <el-table-column :render-header="crud.renderHeader" type="selection" width="60"/>
        <el-table-column :render-header="crud.renderHeader" type="index" width="60" label="序号"/>
        <el-table-column
          v-if="item.visible"
          v-for="(item, index) in crud.header"
          :key="`col_${index}`"
          :prop="item.prop"
          :label="columnLabel(item)"
          :width="item.width + 'px'"
          :data-porp='item.prop'
          @contextmenu.native="showMenu"
          @header-dragend="changeColWidth"
        >
          <!-- 自定义渲染模版 -->
          <template slot-scope="scope">
            <!-- 当列key为 sort 时，渲染一个手柄icon -->
            <template v-if="item.prop =='sort'">
              <div class="handle_move">
                <i :class="scope.row['sort']" />
              </div>
            </template>
            <template v-else>
              <span v-if="item.type == 1" style="margin-left: 0px">{{scope.row[`${item.prop}`]}}</span>
              <span v-if="item.type == 2" style="margin-left: 0px">{{ parseTime(scope.row[`${item.prop}`])}}</span>
              <span v-if="item.type == 3" style="margin-left: 0px">{{ getDict(`this.dict.label.${item.dictionary}["${scope.row[item.prop]}"]`) }}</span>
            </template>
          </template>
        </el-table-column>
<!--        <el-table-column :render-header="crud.renderHeader" v-if="columns.visible('code')" prop="code" label="编码"/>-->
<!--        <el-table-column :render-header="crud.renderHeader" v-if="columns.visible('name')" prop="name" label="名称"/>-->
<!--        <el-table-column :render-header="crud.renderHeader" v-if="columns.visible('isBuy')" prop="isBuy" label="是否采购">-->
<!--          <template slot-scope="scope">-->
<!--            {{ scope.row.isBuy == 1 ? '是' : '否' }}-->
<!--          </template>-->
<!--        </el-table-column>-->
<!--        <el-table-column :render-header="crud.renderHeader" v-if="columns.visible('isSale')" prop="isSale" label="是否销售">-->
<!--          <template slot-scope="scope">-->
<!--            {{ scope.row.isSale == 1 ? '是' : '否' }}-->
<!--          </template>-->
<!--        </el-table-column>-->
<!--        <el-table-column :render-header="crud.renderHeader" v-if="columns.visible('isReturn')" prop="isReturn" label="是否退货">-->
<!--          <template slot-scope="scope">-->
<!--            {{ scope.row.isReturn == 1 ? '是' : '否' }}-->
<!--          </template>-->
<!--        </el-table-column>-->
<!--        <el-table-column :render-header="crud.renderHeader" v-if="columns.visible('isZeroPrice')" prop="isZeroPrice" label="是否零单价" width="100">-->
<!--          <template slot-scope="scope">-->
<!--            {{ scope.row.isZeroPrice == 1 ? '是' : '否' }}-->
<!--          </template>-->
<!--        </el-table-column>-->
<!--        <el-table-column :render-header="crud.renderHeader" v-if="columns.visible('status')" label="状态" prop="status">-->
<!--          <template slot-scope="scope">-->
<!--            {{ dict.label.common_status[scope.row.status] }}-->
<!--          </template>-->
<!--        </el-table-column>-->
<!--        <el-table-column :render-header="crud.renderHeader" v-permission="['admin','basGoodsTag:edit','basGoodsTag:del']" label="操作" width="150px"-->
<!--                         align="center">-->
<!--          <template slot-scope="scope">-->
<!--            <udOperation-->
<!--                :data="scope.row"-->
<!--                :permission="permission"-->
<!--            />-->
<!--          </template>-->
<!--        </el-table-column>-->
      </el-table>
      <!--分页组件-->
      <pagination/>
    </div>
  </div>
</template>

<script>
import crudBasGoodsTag from '@/api/erp/basGoodsTag'
import CRUD, {crud, form, header, presenter} from '@crud/crud'
import rrOperation from '@crud/RR.operation'
import crudOperation from '@crud/CRUD.operation'
import udOperation from '@crud/UD.operation'
import pagination from '@crud/Pagination'

import { publicListKey } from "@/utils/key";
import {getHeaderProperties} from "@/api/erp/headerProperties";
import {tablemixins} from "@/mixins/tablemixins";
import  jTableColumnConfig  from "@/components/jTableColumnConfig/jTableColumnConfig";


// crud交由presenter持有
const defaultCrud = CRUD({title: '商品类型', url: 'api/basGoodsTag', sort: 'code,asc', crudMethod: {...crudBasGoodsTag}})
const defaultForm = {
  id: null,
  code: null,
  name: null,
  type: null,
  isBuy: null,
  isSale: null,
  isReturn: null,
  isZeroPrice: null,
  seq: null,
  status: null,
  remark: null,
  createUserId: null,
  createUserCode: null,
  createUserName: null,
  createTime: null,
  updateUserId: null,
  updateUserCode: null,
  updateUserName: null,
  updateTime: null
}
export default {
  name: 'BasGoodsTag',
  components: {pagination, crudOperation, rrOperation, udOperation,jTableColumnConfig},
  mixins: [presenter(defaultCrud), header(), form(defaultForm), crud(),publicListKey,tablemixins],
  dicts: ['t_bas_goods_brand_type', 'common_status','t_bas_goods_brand_type','common_yes_or_no'],
  data() {
    return {

      permission: {
        add: ['admin', 'basGoodsTag:add'],
        edit: ['admin', 'basGoodsTag:edit'],
        del: ['admin', 'basGoodsTag:del'],
        import: ['admin', 'basGoodsTag:import'],
        export: ['admin', 'basGoodsTag:export'],
        copy: ['admin', 'basGoodsTag:copy'],
        upload: ['admin', 'basGoodsTag:upload'],
        download: ['admin', 'basGoodsTag:download'],
        enable: ['admin', 'basGoodsTag:enable'],
        disable: ['admin', 'basGoodsTag:disable'],
      },
      rules: {
        name: [
          {required: true, message: '名称不能为空', trigger: 'blur'}
        ],
        code: [
          {required: true, message: '编码不能为空', trigger: 'blur'}
        ],
      }
    }
  },
  watch: {},
  updated() {
    this.$nextTick(() => {
      this.$refs.table.doLayout()
    })},
  methods: {
    // 获取数据前设置好接口地址
    [CRUD.HOOK.beforeRefresh]() {
      return true
    }, // 新增与编辑前做的操作
    [CRUD.HOOK.afterToCU](crud, form) {
    },

  }
}
</script>

<style scoped>
.table-img {
  display: inline-block;
  text-align: center;
  background: #ccc;
  color: #fff;
  white-space: nowrap;
  position: relative;
  overflow: hidden;
  vertical-align: middle;
  width: 32px;
  height: 32px;
  line-height: 32px;
}
</style>
